Skip to main content

All Questions

6votes
3answers
786views

Collision detection of two rects with rounded borders

I wrote an algorithm how to detect the collision detection of two rects with rounded borders (the code was written using TypeScript but I tried to name things as clear as possible to code be readable ...
EzioMercer's user avatar
6votes
1answer
182views

Code to generate an array of 364 random special characters with 20 random words broken up throughout

I am trying to recreate a Fallout 4 style terminal hacking game, so I wanted to create code to generate the terminal output (namely, 32 rows with 12 characters each and 20 random words spread out). ...
Dalton's user avatar
3votes
1answer
91views

Merge discrete integer intervals

What it does The code starts with a set of integer intervals, and can add new intervals (possibly by updating existing intervals). Essentially, it is a bit array whose index starts at ...
FromTheStackAndBack's user avatar
3votes
2answers
158views

Basic Linked List Implementation in JavaScript

Clarification of Intent Recursion here is used on purpose for practice - note that iteration is preferred in this case (I'll be more clear about where my intentions are!) Factory function was also ...
bdng's user avatar
2votes
3answers
198views

Efficiently tagging first and last of each object matching condition

How can I make the code more readable and more efficient? (provided code is O(n²) time, but intuition says it can be pre-processed and done in O(n) time) Description it tags the first and last of ...
FromTheStackAndBack's user avatar
1vote
2answers
116views

A simple performant factorial function

I am new to algorithm and data structure. After a little introduction to the topic, I have decided to implement a function called calculateFactorial, which takes an integer and calculates its ...
Napoleon Bonaparte's user avatar
1vote
1answer
57views

Negamax AI for playing Connect Four against Alpha-beta pruning AI in Javascript

The working page is in GitHub. Introduction This time, I have two AI bots playing Connect Four against each other. The first AI bot uses Alpha-beta pruning, and the other one uses a Negamax with Alpha-...
coderodde's user avatar
4votes
0answers
54views

Connect Four AI vs. AI match in Javascript

This time, I have a Javascript program that runs a Connect Four match between two Alpha-beta pruning based AI bots. (See this page.) ai-battle.html: ...
coderodde's user avatar
2votes
1answer
62views

Combining multiple regexps using the `|` operator and grouping the regexps by their flags

I've implemented a function that creates a multiple regular expressions predicate. The idea behind the predicate is combining regular expressions using the disjunction operator ...
terrorrussia-keeps-killing's user avatar
3votes
2answers
95views

Optimizing a Function to Check Pronic Numbers in JavaScript

I've written a function in JavaScript to check whether a given number is a Pronic number. A Pronic number, also known as an oblong number, rectangular number, or ...
TAHER El Mehdi's user avatar
2votes
1answer
108views

Move timestamp to the next Monday 10:01 AM [closed]

I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
Slazer's user avatar
7votes
1answer
232views

Find the longest "common sequence" in two lists

In short, the algorithm must find the longest sequence that joins together common sequences from two lists (a more formal specification is given in the code's header). The lists are assumed to contain ...
user266319's user avatar
2votes
2answers
75views

Calculating the sum of all k-sized sub-arrays in an array using sliding window algorithm

I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why? ...
Alekam's user avatar
3votes
1answer
134views

Recursive Factorial Calculation in JavaScript

...
TAHER El Mehdi's user avatar
4votes
2answers
341views

Count matching pairs (modular equality)

Problem Given an array of natural numbers a. Find the number of such pairs of elements (a_i, a_j), where ...
EzioMercer's user avatar

153050per page
close